﻿using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Effects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Documents;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using 纸片人.ConvertClass;
using 纸片人.PageViews;
using 纸片人.win2dEffectControl.DataClass;

using 纸片人.CalculateControls;
// The Templated Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234235

namespace 纸片人.win2dEffectControl
{
    public class TurbulenceEffectControl : EffectOutputControl
    {

        private ComboBox noiseCmoboBox;

        private TextBoxSlider octavesSlider;
        private TextBoxSlider seedSlider;
                               
        private Vector2Control sizeVector2Control;
        private Vector2Control offsetVector2Control;
        private Vector2Control frequencyVector2Control;


        private CheckBox tileableCheckBox;
        List<TurbulenceEffectNoise> listTurbulenceNoise = new List<TurbulenceEffectNoise>();

      

        private TurbulenceEffectData turbulenceEfffectData;

        public TurbulenceEffectControl()
        {
            this.DefaultStyleKey = typeof(TurbulenceEffectControl);
            EffectData = turbulenceEfffectData = new TurbulenceEffectData();
            listTurbulenceNoise = EffectUtil.GetEnumList<TurbulenceEffectNoise>();
            this.Loaded += TurbulenceEffectControl_Loaded;
        }

        private void TurbulenceEffectControl_Loaded(object sender, RoutedEventArgs e)
        {

            if (turbulenceEfffectData != null)
            {
                var tur = Effect as TurbulenceEffect;
                sizeVector2Control.Vector2 =(turbulenceEfffectData.EffectSize);
                offsetVector2Control.Vector2=(turbulenceEfffectData.Offset);
                frequencyVector2Control.Vector2=(turbulenceEfffectData.Frequency);
            }

        }

       


        /// <summary>
        /// 初始化模板内容
        /// </summary>
        protected override void OnApplyTemplate()
        {

            

            base.OnApplyTemplate();

            effectBlockName.Text = "湍流效应";

            //大小
            sizeVector2Control = GetTemplateChildFormName<Vector2Control>(nameof(sizeVector2Control));
            SetVector2Control(sizeVector2Control, turbulenceEfffectData, nameof(TurbulenceEffectData.EffectSize));
           


            //偏移
            offsetVector2Control = GetTemplateChildFormName<Vector2Control>(nameof(offsetVector2Control));
            SetVector2Control(offsetVector2Control, turbulenceEfffectData, nameof(TurbulenceEffectData.Offset));



            //频率
            frequencyVector2Control = GetTemplateChildFormName<Vector2Control>(nameof(frequencyVector2Control));
            frequencyVector2Control.StepFrequency = 0.001;

       
            SetVector2Control(frequencyVector2Control, turbulenceEfffectData, nameof(TurbulenceEffectData.Frequency));




            //八度
            octavesSlider = GetTemplateChildFormName<TextBoxSlider>(nameof(octavesSlider));
            SetTextBoxSlider(octavesSlider, turbulenceEfffectData, nameof(TurbulenceEffectData.Octaves));
           
           

            seedSlider = GetTemplateChildFormName<TextBoxSlider>(nameof(seedSlider));
            SetTextBoxSlider(seedSlider, turbulenceEfffectData, nameof(TurbulenceEffectData.Seed));


            noiseCmoboBox = GetTemplateChildFormName<ComboBox>(nameof(noiseCmoboBox));
            SetComboBox(noiseCmoboBox, listTurbulenceNoise, turbulenceEfffectData, nameof(TurbulenceEffectData.Noise));

            tileableCheckBox = GetTemplateChildFormName<CheckBox>(nameof(tileableCheckBox));
            SetCheckBox(tileableCheckBox, turbulenceEfffectData, nameof(TurbulenceEffectData.Tileable));

        }

       
    }
}
